package com.dc.controller;

import com.dc.annotation.Log;
import com.dc.common.ResponseResultVO;
import com.dc.entity.SysDataSource;
import com.dc.entity.SysRole;
import com.dc.entity.SysUser;
import com.dc.entity.ro.SysUserRO;
import com.dc.entity.ro.SysUserRoleRO;
import com.dc.service.SysUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 管理员用户
 */
@Api(tags = "后台-管理员用户接口")
@Controller
@RequestMapping(value = "/sys/user")
@RestController
public class SysUserController {

    @Resource
    private SysUserService sysUserService;

    @Log(title = "管理员用户", businessDesc = "新增管理员用户")
    @ApiOperation(value = "新增管理员用户", notes = "新增管理员用户")
    @RequestMapping(value = "/insert", method = RequestMethod.POST)
    public ResponseResultVO insert(@RequestBody SysUserRO sysUserRO) {
        return sysUserService.insert(sysUserRO);
    }

    @Log(title = "管理员用户", businessDesc = "新增数据源")
    @ApiOperation(value = "新增数据源", notes = "新增数据源")
    @RequestMapping(value = "/insertDataSource", method = RequestMethod.POST)
    public ResponseResultVO insertDataSource(@RequestBody SysDataSource sysDataSource) {
        return sysUserService.insertDataSource(sysDataSource);
    }

    @Log(title = "管理员用户", businessDesc = "切换数据源")
    @ApiOperation(value = "切换数据源", notes = "切换数据源")
    @RequestMapping(value = "/updateDataSource", method = RequestMethod.GET)
    public ResponseResultVO updateDataSource(String id) {
        return sysUserService.updateDataSource(id);
    }

    @Log(title = "管理员用户", businessDesc = "删除管理员用户")
    @ApiOperation(value = "删除管理员用户", notes = "删除管理员用户")
    @RequestMapping(value = "/delete", method = RequestMethod.GET)
    public ResponseResultVO delete(@RequestParam(value = "id") String id) {
        return sysUserService.delete(id);
    }


    @Log(title = "管理员用户", businessDesc = "修改管理员用户")
    @ApiOperation(value = "修改管理员用户", notes = "修改管理员用户")
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    public ResponseResultVO update(@RequestBody SysUserRO sysUserRO) {
        return sysUserService.update(sysUserRO);
    }

    @Log(title = "管理员用户", businessDesc = "修改个人账号信息")
    @ApiOperation(value = "修改个人账号信息", notes = "修改个 人账号信息")
    @RequestMapping(value = "/updateUserInfo", method = RequestMethod.POST)
    public ResponseResultVO updateUserInfo(@RequestBody SysUserRO sysUserRO) {
        return sysUserService.updateUserInfo(sysUserRO);
    }

    @Log(title = "管理员用户", businessDesc = "修改个人账号密码")
    @ApiOperation(value = "修改个人账号密码", notes = "修改个人账号密码")
    @RequestMapping(value = "/updateUserPwd", method = RequestMethod.POST)
    public ResponseResultVO updateUserPwd(@RequestBody SysUserRO sysUserRO) {
        return sysUserService.updateUserPwd(sysUserRO);
    }

    @Log(title = "管理员用户", businessDesc = "修改用户头像")
    @ApiOperation(value = "修改用户头像", notes = "修改用户头像")
    @RequestMapping(value = "/updatePortrait", method = RequestMethod.GET)
    public ResponseResultVO updatePortrait(String portrait) {
        return sysUserService.updatePortrait(portrait);
    }

    @ApiOperation(value = "用户解锁", notes = "用户解锁")
    @RequestMapping(value = "/unlock", method = RequestMethod.GET)
    public ResponseResultVO unlock(String id) {
        return sysUserService.unlock(id);
    }


    @ApiOperation(value = "查询管理员用户详情", notes = "查询管理员用户详情")
    @RequestMapping(value = "/selectById", method = RequestMethod.GET)
    public ResponseResultVO<SysUser> selectById(@RequestParam(value = "id") String id) {
        return sysUserService.selectById(id);
    }


    @ApiOperation(value = "查询管理员用户列表", notes = "查询管理员用户")
    @RequestMapping(value = "/selectSysUserList", method = RequestMethod.POST)
    public ResponseResultVO<SysUser> selectSysUserList(@RequestBody SysUserRO ro) {
        return sysUserService.selectSysUserList(ro);
    }

    @ApiOperation(value = "查询所有用户列表不分页", notes = "查询所有用户列表不分页")
    @RequestMapping(value = "/selectAllUser", method = RequestMethod.GET)
    public ResponseResultVO<List<SysUser>> selectAllUser() {
        return sysUserService.selectAllUser();
    }

    @Log(title = "管理员用户", businessDesc = "修改管理员用户角色")
    @ApiOperation(value = "修改管理员用户角色", notes = "修改管理员用户角色")
    @RequestMapping(value = "/updateSysUserRole", method = RequestMethod.POST)
    public ResponseResultVO updateSysUserRole(@RequestBody SysUserRoleRO ro) {
        return sysUserService.updateSysUserRole(ro);
    }


    @ApiOperation(value = "查询管理员用户角色列表", notes = "查询管理员用户角色列表")
    @RequestMapping(value = "/selectSysUserRoleList", method = RequestMethod.GET)
    public ResponseResultVO<SysRole> selectSysUserRoleList(@RequestParam(value = "id") String id) {
        return sysUserService.selectSysUserRoleList(id);
    }


}
